// components/receive/cancellation/cancellation.js
import api from '../../../utils/api';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    claimId:''
  },

  /**
   * 组件的初始数据
   */
  data: {
    message:''
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onChange(e){
      this.setData({
        message:e.detail
      })
    },
    // 取消
    onCancle(){
      this.setData({
        message:''
      })
      this.triggerEvent('myevent', 'cancle')
    },
    // 提交
    onSubmit() {
      let that = this;
      api.abolishClaim({
        data:{
          claimId:that.data.claimId,
          reason:that.data.message
        },
        method:'POST',
        success:function(res){
          if(res.data.code==200){
            if(!res.data.data){
              wx.showToast({
                title: res.data.message,
              })
              setTimeout(() => {
                wx.navigateBack({
                  delta: 1,
                })
              }, 100);
            }else{
              wx.navigateTo({
                url: '/pages/receive/invalidDetails/invalidDetails?abolishId='+res.data.data,
              })
            }
            that.triggerEvent('myevent', 'cancle')
            
          }else{
            wx.showModal({
              content:res.data.message,
              showCancel:false,
              confirmColor:'#0041C4'
            })
          }
        }
      })
    }
  }
})
